/*
 moxl - Modular XML Library
 Copyright (c) 2007, Malcolm Sparks

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package moxl.tokenizer;

/**
 * Provides useful tests for character encodings. Currently this class only supports tests on UTF-8 and not yet on UTF-16 characters.
 */
public class CodePage
{
	/**
	 * Not intended to be instantiated.
	 */
	private CodePage() {
	}
	
	/**
	 * Is this a valid XML Letter?
	 */
	public static boolean isLetter(int character)
	{
		if (character >= 0x41 && character <= 0x5a)
		{
			return true;
		}
		if (character >= 0x61 && character <= 0x7a)
		{
			return true;
		}
		if (character >= 0xc0 && character <= 0xd6)
		{
			return true;
		}
		if (character >= 0xd8 && character <= 0xf6)
		{
			return true;
		}
		if (character >= 0xf8 && character <= 0xff)
		{
			return true;
		}
		return false;
	}

	public static boolean isNameChar(int character)
	{
		if (isLetter(character))
		{
			return true;
		}
		if (isDigit(character))
		{
			return true;
		}
		if (character == '.' || character == '-' || character == ':')
		{
			return true;
		}
		if (isCombiningChar(character))
		{
			return true;
		}
		if (isExtender(character))
		{
			return true;
		}
		return false;
	}

	public static boolean isNCNameChar(int character)
	{
		if (isLetter(character))
		{
			return true;
		}
		if (isDigit(character))
		{
			return true;
		}
		if (character == '.' || character == '-' || character == '_')
		{
			return true;
		}
		if (isCombiningChar(character))
		{
			return true;
		}
		if (isExtender(character))
		{
			return true;
		}
		return false;
	}

	public static boolean isDigit(int character)
	{
		if (character >= 0x30 && character <= 0x39)
		{
			return true;
		}
		return false;
	}

	public static boolean isExtender(int character)
	{
		if (character == 0xb7)
		{
			return true;
		}
		return false;
	}

	public static boolean isCombiningChar(int character)
	{
		return false;
	}

	public static boolean isWhitespace(int character)
	{
		return character == ' ' || character == '\t' || character == '\r' || character == '\n';
	}

}
